package com.fzu.mmdbproxyframework.cluster.passcloud;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.fzu.mmdbproxyframework.cluster.cloudstack.IntNic;
import com.fzu.mmdbproxyframework.cluster.cloudstack.IntSecurityGroup;
import com.fzu.mmdbproxyframework.cluster.cloudstack.IntVM;
import com.fzu.mmdbproxyframework.cluster.cloudstack.IntVMList;

import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONObject;

public class VMOperation {

	private static final VMOperation vmOperation =new VMOperation();
	private VMOperation(){	
	}
	public static VMOperation getInstance(){
		SendRequest.login("lzq","lzq","DBM");//登陆CloudStack
		return vmOperation;
	}
	@SuppressWarnings("unchecked")
	public IntVMList listAllVirtualMachinesInternetware(
			HashMap<String, String> params) {
		String result = SendRequest.sendRequest(InternetwareCmd.ListAllVMsCmd,
				params);
		if(null==result){
			return null;
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(InternetwareCmd.ListAllVMsRes);
		Map classMap = new HashMap();
		classMap.put("virtualmachine", IntVM.class);
		classMap.put("nic", IntNic.class);
		classMap.put("securitygroup", IntSecurityGroup.class);
		try {
			IntVMList vms = (IntVMList) JSONObject.toBean(obj, IntVMList.class,
					classMap);
			return vms;
		} catch (JSONException e) {
			System.out.println(e);
		}
		return null;
	}

	public Boolean stopVMInternetware(String id, boolean forced) {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("id", id);
		if (forced) {
			params.put("forced", "true");
		}
		boolean success = false;
		String result = SendRequest.sendRequest(InternetwareCmd.StopVMCmd,
				params);
		if(null == result){
			return success;
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.StopVMRes);
		if(null == obj || obj.has("errorcode")){
			return success;
		}
		JSONObject obj2 = QueryAsyncJob.sendAsynRequest(obj.getString("jobid"));
		if (obj2.getInt("jobstatus") == 1) {
			success = true;
			return success;
		}
		return success;
	}

	public Boolean startVMInternetware(String id) {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("id", id);
		boolean success = false;
		String result = SendRequest.sendRequest(InternetwareCmd.StartVMCmd,
				params);
		if(null == result){
			return success;
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.StartVMRes);
		if(null == obj || obj.has("errorcode")){
			return success;
		}
		JSONObject obj2 = QueryAsyncJob.sendAsynRequest(obj.getString("jobid"));
		if (obj2.getInt("jobstatus") == 1) {
			success = true;
			return success;
		}
		return success;
	}

	public Boolean rebootVMInternetware(String id) {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("id", id);
		boolean success = false;
		String result = SendRequest.sendRequest(InternetwareCmd.RebootVMCmd,
				params);
		if(null == result){
			return success;
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.RebootVMRes);
		if(null == obj || obj.has("errorcode")){
			return success;
		}
		JSONObject obj2 = QueryAsyncJob.sendAsynRequest(obj.getString("jobid"));
		if (obj2.getInt("jobstatus") == 1) {
			success = true;
			return success;
		}
		return success;
	}

//	public Boolean deleteVirtualMachine(String id) {
//		HashMap<String, String> params = new HashMap<String, String>();
//		params.put("id", id);
//		params.put("expunge", "true");
//		Boolean success = false;
//		String result = SendRequest.sendRequest(InternetwareCmd.DestroyVMCmd,
//				params);
//		if(null == result){
//			return success;
//		}
//		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
//				InternetwareCmd.DestroyVMRes);
//		if(null == obj || obj.has("errorcode")){
//			return success;
//		}
//		JSONObject obj2 = QueryAsyncJob.sendAsynRequest(obj.getString("jobid"));
//		if (obj2.getInt("jobstatus") == 1) {
//			success = true;
//			return success;
//		}
//		return success;
//	}
//	public Boolean recoverVM(String id) {
//		HashMap<String, String> params = new HashMap<String, String>();
//		params.put("id", id);
//		Boolean success = false;
//		String result = SendRequest.sendRequest(InternetwareCmd.recoverVMCmd,
//				params);
//		if(null == result){
//			return success;
//		}
//		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
//				InternetwareCmd.recoverVMRes);
//		if(null == obj || obj.has("errorcode")){
//			return success;
//		}
//		success = true;
//		return success;
//	}

	public String deployVirtualMachineInternetware(
			HashMap<String, String> params) {
		String result = SendRequest.sendRequest(InternetwareCmd.DeployVMCmd,
				params);
		if (null == result){
			return "fail";
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.DeployVMRes);
		if(null == obj || obj.has("errorcode")){
			return "fail";
		}
		JSONObject obj2 = QueryAsyncJob.sendAsynRequest(obj.getString("jobid"));
		if (obj2.getInt("jobstatus") == 1) {
			String serverId = obj2.getJSONObject("jobresult").getJSONObject(
					"virtualmachine").getString("id");
			return serverId;
		}
		return "fail";
	}

	public String deployVirtualMachineFromSnapshot(
			HashMap<String, String> params) {
		String result = SendRequest.sendRequest(
				InternetwareCmd.DeployVMFromSnapshotCmd, params);
		if (null == result){
			return "fail";
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.DeployVMRes);
		if(null == obj || obj.has("errorcode")){
			return "fail";
		}
		JSONObject obj2 = QueryAsyncJob.sendAsynRequest(obj.getString("jobid"));
		if (obj2.getInt("jobstatus") == 1) {
			String serverId = obj2.getJSONObject("jobresult").getJSONObject(
					"virtualmachine").getString("id");
			return serverId;
		}
		return "fail";
	}

	public Boolean changeServiceForVirtualMachineInternetware(
			String serviceOfferingId, String VMId) {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("serviceofferingid", serviceOfferingId);
		params.put("id", VMId);
		Boolean success = false;
		String result = SendRequest.sendRequest(
				InternetwareCmd.ChangeServiceForVMCmd, params);
		if(null == result){
			return success;
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.ChangeServiceForVMRes);
		if(null == obj || obj.has("errorcode")){
			return success;
		}
		success = true;
		return success;
	}

	public Boolean attachIso(HashMap<String, String> params) {
		Boolean success = false;
		String result = SendRequest.sendRequest(InternetwareCmd.attachIsoCmd,
				params);
		if(null == result){
			return success;
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.attachIsoRes);
		if(null == obj || obj.has("errorcode")){
			return success;
		}
		JSONObject obj2 = QueryAsyncJob.sendAsynRequest(obj.getString("jobid"));
		if (obj2.getInt("jobstatus") == 1) {
			success = true;
			return success;
		}
		return success;
	}
	
	public Boolean detachIso(HashMap<String, String> params) {
		Boolean success = false;
		String result = SendRequest.sendRequest(InternetwareCmd.detachIsoCmd,
				params);
		if(null == result){
			return success;
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.detachIsoRes);
		if(null == obj || obj.has("errorcode")){
			return success;
		}
		JSONObject obj2 = QueryAsyncJob.sendAsynRequest(obj.getString("jobid"));
		if (obj2.getInt("jobstatus") == 1) {
			success = true;
			return success;
		}
		return success;
	}
	
	
	public Boolean createVMSnapshot(HashMap<String, String> params) {
		Boolean success = false;
		String result = SendRequest.sendRequest(InternetwareCmd.createVMSnapshotCmd,
				params);
		if(null == result){
			return success;
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.createVMSnapshotRes);
		if(null == obj || obj.has("errorcode")){
			return success;
		}
		JSONObject obj2 = QueryAsyncJob.sendAsynRequest(obj.getString("jobid"));
		if (obj2.getInt("jobstatus") == 1) {
			success = true;
			return success;
		}
		return success;
	}
	
	public Boolean migrateVirtualMachineVolumes(HashMap<String, String> params) {
		Boolean success = false;
		params.put("volumeid", "");
		String result = SendRequest.sendRequest(InternetwareCmd.migrateVirtualMachineVolumesCmd,
				params);
		if(null == result){
			return success;
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.migrateVirtualMachineVolumesRes);
		if(null == obj || obj.has("errorcode")){
			return success;
		}
		JSONObject obj2 = QueryAsyncJob.sendAsynRequest(obj.getString("jobid"));
		if (obj2.getInt("jobstatus") == 1) {
			success = true;
			return success;
		}
		return success;
	}
	
	public Boolean migrateVirtualMachine(HashMap<String, String> params) {
		Boolean success = false;
		params.put("volumeid", "");
		String result = SendRequest.sendRequest(InternetwareCmd.migrateVirtualMachineCmd,
				params);
		if(null == result){
			return success;
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.migrateVirtualMachineRes);
		if(null == obj || obj.has("errorcode")){
			return success;
		}
		JSONObject obj2 = QueryAsyncJob.sendAsynRequest(obj.getString("jobid"));
		if (obj2.getInt("jobstatus") == 1) {
			success = true;
			return success;
		}
		return success;
	}
	public Boolean startVM(String id) {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("id", id);
		boolean success = false;
		String result = SendRequest.sendRequest(InternetwareCmd.StartVMCmd,params);
		if(null == result){
			return success;
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.StartVMRes);
		if(null == obj || obj.has("errorcode")){
			return success;
		}
		JSONObject obj2 = QueryAsyncJob.sendAsynRequest(obj.getString("jobid"));
		if (obj2.getInt("jobstatus") == 1) {
			success = true;
			return success;
		}
		return success;
	}
	public Boolean stopVM(String id) {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("id", id);
		params.put("forced", "false");
		boolean success = false;
		String result = SendRequest.sendRequest(InternetwareCmd.StopVMCmd,
				params);
		if(null == result){
			return success;
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.StopVMRes);
		if(null == obj || obj.has("errorcode")){
			return success;
		}
		JSONObject obj2 = QueryAsyncJob.sendAsynRequest(obj.getString("jobid"));
		if (obj2.getInt("jobstatus") == 1) {
			success = true;
			return success;
		}
		return success;
	}
	public Boolean destroyVM(String id) {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("id", id);
		Boolean success = false;
		String result = SendRequest.sendRequest(InternetwareCmd.DestroyVMCmd,
				params);
		if(null == result){
			return success;
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.DestroyVMRes);
		if(null == obj || obj.has("errorcode")){
			return success;
		}
		JSONObject obj2 = QueryAsyncJob.sendAsynRequest(obj.getString("jobid"));
		if (obj2.getInt("jobstatus") == 1) {
			success = true;
			return expungeVirtualMachine(id);
		}
		return success;
	}
	public String getVMStatus(String vmId,String projectId) {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("id", vmId);
		params.put("projectid", projectId);
		String result = SendRequest.sendRequest(InternetwareCmd.ListAllVMsCmd,params);
		if(null==result){
			return "fail";
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(InternetwareCmd.ListAllVMsRes);
		JSONArray vms = obj.getJSONArray("virtualmachine");
		JSONObject vm = vms.getJSONObject(0);
		String status = vm.getString("state");
		return status;
	}
	public HashMap<String,String> deployVM(HashMap<String, String> params) {
		String result = SendRequest.sendRequest(InternetwareCmd.DeployVMCmd,
				params);
		if (null == result){
			return null;
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.DeployVMRes);
		if(null == obj || obj.has("errorcode")){
			return null;
		}
		HashMap<String,String> deployResult = null;
		JSONObject obj2 = QueryAsyncJob.sendAsynRequest(obj.getString("jobid"));
		if (obj2.getInt("jobstatus") == 1) {
			deployResult = new HashMap<String,String>();
			JSONObject vm = obj2.getJSONObject("jobresult").getJSONObject("virtualmachine");
			System.out.println(vm);
			String serverId = vm.getString("id");
			JSONObject nic = vm.getJSONArray("nic").getJSONObject(0);
			String ip = nic.getString("ipaddress");
			deployResult.put("id", serverId);
			deployResult.put("ip", ip);
		}
		return deployResult;
	}
	public ArrayList<HashMap<String, Object>> listProjects() {
		ArrayList<HashMap<String, Object>> dos = new ArrayList<HashMap<String, Object>>();
		String result = SendRequest.sendRequest(InternetwareCmd.ListProjectsCmd, null);
		if (null == result
				|| JSONObject.fromObject(result).getJSONObject(
						InternetwareCmd.ListProjectsRes).isEmpty())
			return null;
		JSONArray obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.ListProjectsRes).getJSONArray("project");
		for (int i = 0; i < obj.size(); i++) {
			JSONObject o = obj.getJSONObject(i);
			HashMap<String, Object> map = InternetwareTool.JSON2Map(o);
			dos.add(map);
		}
		return dos;
	}
	public ArrayList<HashMap<String, Object>> listTemplates(String projectId) {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("projectid", projectId);
		ArrayList<HashMap<String, Object>> templates = new ArrayList<HashMap<String, Object>>();
		String result = SendRequest.sendRequest(
				InternetwareCmd.ListTemplatesCmd, params);
		if (null == result
				|| JSONObject.fromObject(result).getJSONObject(
						InternetwareCmd.ListTemplatesRes).isEmpty())
			return null;
		JSONArray obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.ListTemplatesRes).getJSONArray("template");
		if (null == obj)
			return null;
		for (int i = 0; i < obj.size(); i++) {
			JSONObject o = obj.getJSONObject(i);
			HashMap<String, Object> map = InternetwareTool.JSON2Map(o);
			templates.add(map);
		}
		return templates;
	}
	public ArrayList<HashMap<String, Object>> listFlavors() {
		ArrayList<HashMap<String, Object>> serviceOfferings = new ArrayList<HashMap<String, Object>>();
		String result = SendRequest.sendRequest(InternetwareCmd.ListServiceOfferingsCmd, null);
		if (null == result){
			return null;
		}
		JSONObject json = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.ListServiceOfferingsRes);
		if(json.isEmpty()){
			return null;
		}
		JSONArray obj = json.getJSONArray("serviceoffering");
		for (int i = 0; i < obj.size(); i++) {
			JSONObject o = obj.getJSONObject(i);
			HashMap<String, Object> map = InternetwareTool.JSON2Map(o);
			serviceOfferings.add(map);
		}
		return serviceOfferings;
	}
	public ArrayList<HashMap<String, Object>> listStorages() {
		ArrayList<HashMap<String, Object>> dos = new ArrayList<HashMap<String, Object>>();
		String result = SendRequest.sendRequest(
				InternetwareCmd.ListDiskOfferingsCmd, null);
		if (null == result
				|| JSONObject.fromObject(result).getJSONObject(
						InternetwareCmd.ListDiskOfferingsRes).isEmpty())
			return null;
		JSONArray obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.ListDiskOfferingsRes).getJSONArray(
				"diskoffering");
		for (int i = 0; i < obj.size(); i++) {
			JSONObject o = obj.getJSONObject(i);
			HashMap<String, Object> map = InternetwareTool.JSON2Map(o);
			dos.add(map);
		}
		return dos;
	}
	public ArrayList<HashMap<String, Object>> listZones() {
		ArrayList<HashMap<String, Object>> zones = new ArrayList<HashMap<String, Object>>();
		String result = SendRequest.sendRequest(InternetwareCmd.ListZonesCmd,
				null);
		if (null == result
				|| JSONObject.fromObject(result).getJSONObject(
						InternetwareCmd.ListZonesRes).isEmpty())
			return null;
		JSONArray obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.ListZonesRes).getJSONArray("zone");
		for (int i = 0; i < obj.size(); i++) {
			JSONObject o = obj.getJSONObject(i);
			HashMap<String, Object> map = InternetwareTool.JSON2Map(o);
			zones.add(map);
		}
		return zones;
	}
	public ArrayList<HashMap<String, Object>> listVMNetwork() {
		String result = SendRequest.sendRequest(
				InternetwareCmd.ListVMNetworkCmd, null);
		if (null == result
				|| JSONObject.fromObject(result).getJSONObject(
						InternetwareCmd.ListVMNetworkRes).isEmpty())
			return null;
		ArrayList<HashMap<String, Object>> vmNetworks = new ArrayList<HashMap<String, Object>>();
		JSONArray obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.ListVMNetworkRes).getJSONArray("network");
		for (int i = 0; i < obj.size(); i++) {
			JSONObject o = obj.getJSONObject(i);
			HashMap<String, Object> map = InternetwareTool.JSON2Map(o);
			vmNetworks.add(map);
		}
		return vmNetworks;
	}
	public Boolean expungeVirtualMachine(String id) {
		HashMap<String, String> params = new HashMap<String, String>();
		params.put("id", id);
		Boolean success = false;
		String result = SendRequest.sendRequest(InternetwareCmd.ExpungeVMCmd,
				params);
		if(null == result){
			return success;
		}
		JSONObject obj = JSONObject.fromObject(result).getJSONObject(
				InternetwareCmd.ExpungeVMRes);
		if(null == obj || obj.has("errorcode")){
			return success;
		}
		JSONObject obj2 = QueryAsyncJob.sendAsynRequest(obj.getString("jobid"));
		if (obj2.getInt("jobstatus") == 1) {
			success = true;
			return success;
		}
		return success;
	}

	public static void main(String[] args) {
//		System.out.println(new VMOperation().getVMStatus
//				("21691002-08c9-4a96-ba96-38cfb35b9e00", "f7ce3688-e6c3-48d4-af2d-9476d7743af0"));
//		SendRequest.login("lzq","lzq","DBM");//登陆CloudStack
//		VMOperation vmop=new VMOperation();
//		System.out.println("listVMNetwork="+vmop.listVMNetwork());
//		System.out.println("listZones="+vmop.listZones());
//		System.out.println("listStorages="+vmop.listStorages());
//		System.out.println("listFlavors="+vmop.listFlavors());
//		System.out.println("listZones="+vmop.listZones());
//		System.out.println("listTemplates="+vmop.listTemplates(""));
//		for(HashMap<String,Object> listFlavors : vmop.listFlavors()){
//			if(listFlavors.get("memory").equals(2048)){
//				System.out.println(listFlavors.get("id").toString());
//				System.out.println(listFlavors.get("memory").toString());
//				break;
//			}
//			
//		}
//		System.out.println("destroyVM="+new VMOperation().destroyVM("7210b13b-8f4e-477e-8a01-12bc072b1300"));
//		 HashMap<String, String> params = new HashMap<String, String>();
//		 params.put("projectid", "f7ce3688-e6c3-48d4-af2d-9476d7743af0");
//s		 System.out.println(new VMOperation().listTemplates("f7ce3688-e6c3-48d4-af2d-9476d7743af0"));
//		 params.put("domainid", "9f73970b-ea28-4919-986e-6fd21c7ef859");
//		 System.out.println(new
//		 VMOperation().listAllVirtualMachinesInternetware(
//		 params).getVirtualmachine().get(1).getId());
//		 System.out.println(new VMOperation().listVMConfiguration(params));
		// JSONObject ob=new
		// VMOperation().startVM("67c6ca7c-f2bf-467f-8bea-a88737d7532f0");
//		 params.put("virtualmachineid", "58b98444-650a-498e-a10d-c0a8e00ce6ec");
//		 params.put("hostid", "b67a6ca7-49d8-46ac-a156-083b10161e9b");
//		 params.put("livemigrate", "true");
//		 System.out.println(new VMOperation().recoverVM("58b98444-650a-498e-a10d-c0a8e00ce6ec"));
//		 System.out.println(new
//		 VMOperation().destroyVirtualMachine("9ddc0ebe-845f-46f4-a945-7acfd8ad6227"));
////
//		HashMap<String, String> params = new HashMap<String, String>();
//		params.put("serviceofferingid", "0a1bf299-3506-4cf8-a92b-7086d8ca8a61");
//		params.put("diskofferingid", "8f9909e2-9a00-446d-b425-9264806555ce");
//		params.put("size", "2");
//		params.put("templateid", "c198a45e-1f90-4b76-ab69-037df4635c3a");
//		params.put("zoneid", "f5151efd-5903-465b-be70-660520f80ed1");
//		params.put("name", "deployVMTest");
//		params.put("displayname", "testServer");
//		params.put("networkids", "565e0eaf-944c-4124-8c40-bd350570e971");
//		System.out.println(new VMOperation().deployVM(params));

		
		SendRequest.login("lzq","lzq","DBM");//登陆CloudStack
		VMOperation vmOperation = new VMOperation();
		ArrayList<HashMap<String, Object>> listStorages = vmOperation.listStorages();
		System.out.println(listStorages);//name=SharedNetwork
		for(HashMap<String, Object> maplistFlavors:listStorages){
			if(maplistFlavors.get("disksize")!=null && maplistFlavors.get("disksize").equals(10)){
				System.out.println(maplistFlavors.get("disksize").equals(10));
				System.out.println(maplistFlavors.get("id"));
				break;
			}
			
		}
//		VM vm = new VM();
//		vm.setMemory(2048);
//		for(HashMap<String, Object> mapFlavors:vmOperation.listFlavors()){
//			if(mapFlavors.get("memory").equals(vm.getMemory())){
//				System.out.println(mapFlavors.get("id").toString());
//				vm.setServiceofferingid(mapFlavors.get("id").toString());
//				break;
//			}
//		}
//		for(HashMap<String, Object> mapTemplates:vmOperation.listTemplates("")){
//			if(mapTemplates.get("name").equals("h2Server")){
//				System.out.println(mapTemplates.get("id").toString());
//				vm.setTemplateid(mapTemplates.get("id").toString());
//			}
//		}
//		for(HashMap<String, Object> mapStorages:vmOperation.listStorages()){
//			if(mapStorages.get("disksize").equals("100")){
//				System.out.println(mapStorages.get("id").toString());
//				vm.setDiskofferingid(mapStorages.get("id").toString());
//			}
//			
//		}
//		for(HashMap<String, Object> mapZones:vmOperation.listZones()){
//			if(mapZones.get("name").equals("DataCenter")){
//				System.out.println("--mapZones-name--");
//				System.out.println(mapZones.get("id").toString());
//				vm.setZoneid(mapZones.get("id").toString());
//			}
//			
//		}
//		vm.setProjectid("");
////		String uuid = UUID.randomUUID().toString();
//		vm.setDisplayname("h2Server0001");
//		vm.setName("h2Server0001");
//		HashMap<String, String> params = new HashMap<String, String>();
//		params.put("serviceofferingid", vm.getServiceofferingid());
////		params.put("diskofferingid", vm.getDiskofferingid());
//		params.put("templateid", vm.getTemplateid());
//		params.put("zoneid", vm.getZoneid());
//		params.put("name", vm.getName());
//		params.put("displayname", vm.getDisplayname());
//		System.out.println(vmOperation.deployVM(params));
	}
		// System.out.println(new
		// VMOperation().changeServiceForVirtualMachineInternetware
		// ("d1ff1d64-cf86-4e14-b9ad-2244d327d1b5",
		// "7281b1cd-393e-449f-a395-a180489cc979"));

//		 System.out.println(new VMOperation().listVMConfiguration(params));

	
}
